package formularios;

import clases.Profesor;
import clases.Seccion;
import java.util.LinkedList;
import java.util.ListIterator;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

public class FormularioSeccion extends javax.swing.JFrame {

    LinkedList<JTextField> textos;
    Seccion seccion;

    public FormularioSeccion() {
        initComponents();
        textos = new LinkedList<JTextField>();
        textos.add(txtApellido);
        textos.add(txtCedula);
        textos.add(txtNombre);
        textos.add(txtTitulo);
        textos.add(txtNumero);
    }

    public void setSeccion(Seccion seccion) {
        this.seccion = seccion;
    }

    public void limpiar(){
     ListIterator<JTextField> ite2=textos.listIterator();
        while (ite2.hasNext()){
            JTextField texto= ite2.next();
            texto.setText("");
        }
    }

    private void initComponents() {

        jPanel2 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        txtNombre = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        txtCedula = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        txtTitulo = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        txtApellido = new javax.swing.JTextField();
        jPanel4 = new javax.swing.JPanel();
        btnCancelar = new javax.swing.JButton();
        btnSalir = new javax.swing.JButton();
        btnAceptar = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        txtNumero = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Registre de Seccion y Profesor");
        getContentPane().setLayout(null);

        jPanel2.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPanel2.setLayout(null);

        jLabel2.setFont(new java.awt.Font("Arial", 0, 15)); 
        jLabel2.setText("Nombre del Profesor:");
        jPanel2.add(jLabel2);
        jLabel2.setBounds(30, 60, 200, 18);

        txtNombre.setFont(new java.awt.Font("Arial", 0, 15)); 
        jPanel2.add(txtNombre);
        txtNombre.setBounds(220, 60, 130, 28);

        jLabel3.setFont(new java.awt.Font("Arial", 0, 15)); 
        jLabel3.setText("Cedula del Profesor:");
        jPanel2.add(jLabel3);
        jLabel3.setBounds(30, 20, 200, 18);

        txtCedula.setFont(new java.awt.Font("Arial", 0, 15)); 
        jPanel2.add(txtCedula);
        txtCedula.setBounds(220, 20, 130, 28);

        jLabel4.setFont(new java.awt.Font("Arial", 0, 15)); 
        jLabel4.setText("Titulo Obtenido del Profesor:");
        jPanel2.add(jLabel4);
        jLabel4.setBounds(30, 140, 200, 18);

        txtTitulo.setFont(new java.awt.Font("Arial", 0, 15)); 
        jPanel2.add(txtTitulo);
        txtTitulo.setBounds(220, 140, 130, 28);

        jLabel5.setFont(new java.awt.Font("Arial", 0, 15)); 
        jLabel5.setText("Apellido del Profesor:");
        jPanel2.add(jLabel5);
        jLabel5.setBounds(30, 100, 200, 18);

        txtApellido.setFont(new java.awt.Font("Arial", 0, 15)); 
        jPanel2.add(txtApellido);
        txtApellido.setBounds(220, 90, 130, 28);

        getContentPane().add(jPanel2);
        jPanel2.setBounds(20, 120, 360, 190);

        jPanel4.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPanel4.setLayout(null);

        btnCancelar.setFont(new java.awt.Font("Arial", 0, 15)); 
        btnCancelar.setText("Cancelar");
        btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarActionPerformed(evt);
            }
        });
        jPanel4.add(btnCancelar);
        btnCancelar.setBounds(140, 10, 100, 30);

        btnSalir.setFont(new java.awt.Font("Arial", 0, 15)); 
        btnSalir.setText("Salir");
        btnSalir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSalirActionPerformed(evt);
            }
        });
        jPanel4.add(btnSalir);
        btnSalir.setBounds(260, 10, 80, 30);

        btnAceptar.setFont(new java.awt.Font("Arial", 0, 15)); 
        btnAceptar.setText("Aceptar");
        btnAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAceptarActionPerformed(evt);
            }
        });
        jPanel4.add(btnAceptar);
        btnAceptar.setBounds(20, 10, 110, 30);

        getContentPane().add(jPanel4);
        jPanel4.setBounds(20, 320, 360, 60);

        jPanel3.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPanel3.setLayout(null);

        jLabel1.setFont(new java.awt.Font("Arial", 0, 15)); 
        jLabel1.setText("Numero de la Seccion:");
        jPanel3.add(jLabel1);
        jLabel1.setBounds(30, 20, 200, 18);

        txtNumero.setFont(new java.awt.Font("Arial", 0, 15)); 
        jPanel3.add(txtNumero);
        txtNumero.setBounds(210, 20, 130, 28);

        getContentPane().add(jPanel3);
        jPanel3.setBounds(20, 20, 360, 80);

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-402)/2, (screenSize.height-427)/2, 402, 427);
    }

    private void btnAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAceptarActionPerformed
     
          ListIterator<JTextField> ite2=textos.listIterator();
        while (ite2.hasNext()){
            JTextField texto= ite2.next();
            if(texto.getText().equals("")){
                   JOptionPane.showMessageDialog(new JFrame(),"Existen campos vavios","Registre de Seccion y Profesor",JOptionPane.WARNING_MESSAGE);
                   return;
            }
        }
        if(!seccion.getNumero_sec().equals("")){
                   JOptionPane.showMessageDialog(new JFrame(),"La seccion ya se creo","Registre de Seccion y Profesor",JOptionPane.WARNING_MESSAGE);
                   return;
        }
        if(seccion.getProfesorAsignado()!=null){
                   JOptionPane.showMessageDialog(new JFrame(),"El profesor ya ha sido asignado","Registre de Seccion y Profesor",JOptionPane.WARNING_MESSAGE);
                   return;
        }
        seccion.setNumero_sec(txtNumero.getText());
        seccion.setProfesorAsignado(new Profesor(txtCedula.getText(), txtNombre.getText(), txtApellido.getText(),txtTitulo.getText()));
        JOptionPane.showMessageDialog(new JFrame(),"La seccion se creo exitosamente y el profesor ha sido asignado","Registre de Seccion y Profesor",JOptionPane.INFORMATION_MESSAGE);
        limpiar();
    }

    private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {
     
        limpiar();
    }

    private void btnSalirActionPerformed(java.awt.event.ActionEvent evt) {
     
        dispose();
    }

    
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new FormularioSeccion().setVisible(true);
            }
        });
    }

    
    private javax.swing.JButton btnAceptar;
    private javax.swing.JButton btnCancelar;
    private javax.swing.JButton btnSalir;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JTextField txtApellido;
    private javax.swing.JTextField txtCedula;
    private javax.swing.JTextField txtNombre;
    private javax.swing.JTextField txtNumero;
    private javax.swing.JTextField txtTitulo;
    

}
